<template>
  <a-modal
    :title="isEdit ? '修改附加属性' : '添加附加属性'"
    :visible="show"
    :confirm-loading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    :maskClosable="false"
    width="30%"
    class="basic-modal"
  >
    <div class="title">
      <a-form-model
        :label-col="{ span: 6 }"
        :wrapper-col="{ span: 14 }"
        :model="reviseForm"
        :rules="reviseformRules"
        ref="reviseForm"
      >
        <a-form-model-item
          label="附加属性名称"
          required
          prop="ExtAttributeName"
        >
          <a-input v-model="reviseForm.ExtAttributeName" />
        </a-form-model-item>
        <a-form-model-item label="附加属性值" required prop="ExtAttributeValue">
          <a-input v-model="reviseForm.ExtAttributeValue" />
        </a-form-model-item>
        <a-form-model-item label="附加属性描述">
          <a-textarea
            style="resize: none"
            v-model="reviseForm.ExtAttributeDesc"
          />
        </a-form-model-item>
      </a-form-model>
    </div>
  </a-modal>
</template>

<script>
import { insExtAttribute, updExtAttribute } from "@/api/basic-type/index";
export default {
  props: ["show", "isEdit", "reviseForm"],
  data() {
    return {
      confirmLoading: false, //确认loading
      reviseformRules: {
        ExtAttributeName: [
          { required: true, message: "请填写附加属性名称", trigger: "blur" },
        ],
        ExtAttributeValue: [
          { required: true, message: "请填写附加属性值", trigger: "blur" },
        ],
      }, //附加属性校验
    };
  },
  methods: {
    //关闭弹窗
    handleCancel() {
      this.$refs.reviseForm.clearValidate();
      this.$emit("update:show", false);
    },
    //确认添加/修改
    handleOk() {
      this.$refs.reviseForm.validate(async (valid) => {
        if (valid) {
          this.confirmLoading = true;
          //true为修改 false为新增
          if (this.isEdit) {
            const res = await updExtAttribute([this.reviseForm]);
            if (res.Data == "") {
              this.$message.info("修改成功");
              this.handleCancel();
              this.$emit("break");
            } else {
              this.$message.info(res.Data);
            }
            this.confirmLoading = false;
          } else {
            const res = await insExtAttribute([this.reviseForm]);
            if (res.Data == "") {
              this.$message.info("添加成功");
              this.handleCancel();
              this.$emit("break");
            } else {
              this.$message.console.error();
              res.Data;
            }
            this.confirmLoading = false;
          }
        }
      });
    },
    //表格选择
    handleTableChange() {},
  },
};
</script>

<style lang="less" scoped></style>
